using System.Collections.Generic;
using UnityEngine;

public static class Main
{
	public static Transform CanvasChildNew(Transform parent, GameObject child)
	{
		Transform transform = Object.Instantiate(child, parent).transform;
		transform.SetParent(parent);
		transform.localScale = Vector3.one;
		transform.localRotation = Quaternion.identity;
		return transform;
	}

	public static Transform CanvasChildNew(Transform parent, GameObject child, Vector2 position)
	{
		Transform transform = CanvasChildNew(parent, child);
		transform.localPosition = position;
		return transform;
	}

	public static Vector3 WorldToCanvasPosition(Vector3 position)
	{
		position = Camera.main.WorldToViewportPoint(position) - new Vector3(0.5f, 0.5f);
		position.Set(position.x * 1920f, position.y * 1080f, 0f);
		return position;
	}

	public static bool RandomBool()
	{
		return Random.value > 0.5f;
	}

	public static int RandomSign()
	{
		return (!(Random.value > 0.5f)) ? 1 : (-1);
	}

	public static Vector2 RandomNormalizedVector2()
	{
		float value = Random.value;
		return new Vector2(value * (float)RandomSign(), (1f - value) * (float)RandomSign());
	}

	public static Vector3 RandomNormalizedVector3()
	{
		float value = Random.value;
		return new Vector3(value * (float)RandomSign(), (1f - value) * (float)RandomSign());
	}

	public static Vector3 RandomVector3(int range)
	{
		return new Vector3(Random.Range(-range, range + 1), Random.Range(-range, range + 1));
	}

	public static Vector3 RandomVector3(int x, int y)
	{
		return new Vector3(Random.Range(-x, x + 1), Random.Range(-y, y + 1));
	}

	public static float CalculateRotation(Vector2 direction)
	{
		return Mathf.Atan2(direction.y, direction.x) * 57.29578f + 90f;
	}

	public static T[] GetAllChildrenWithTag<T>(Transform parent, string tag)
	{
		List<T> list = new List<T>();
		foreach (Transform item in parent)
		{
			if (item.tag == tag)
			{
				list.Add(item.GetComponent<T>());
			}
		}
		return list.ToArray();
	}

	public static Vector3 GetMouseWorldPosition()
	{
		Vector3 mousePosition = Input.mousePosition;
		mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);
		mousePosition.z = 0f;
		return mousePosition;
	}

	public static void Print(params object[] vs)
	{
		string text = string.Empty;
		foreach (object obj in vs)
		{
			text = string.Concat(text, obj, "\t\t");
		}
		Debug.Log(text);
	}
}
